#include<bits/stdc++.h>
using namespace std;
const int MAXN=2e5;
int a[MAXN+5];
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int T,n;
    scanf("%d",&T);
    for(int p=1;p<=T;p++){
        scanf("%d",&n);
        for(int i=1;i<=n;i++){
            scanf("%d",&a[i]);
        }
        int ans=-1;
        for(int s=0;s<(1<<n);s++){
            int x=0,y=0,sum=0;
            for(int i=1;i<=n;i++){
                if(s&(1<<i-1)){
                    if(x&&a[i]==a[x]) sum+=a[i];
                    x=i;
                }else{
                    if(y&&a[i]==a[y]) sum+=a[i];
                    y=i;
                }
            }
            ans=max(ans,sum);
        }
        printf("%d\n",ans);
    }
    return 0;
}//180pts,180pts!!!!!!!!
